// 子模块中的state有两种写法
// 1.对象写法
// 2.函数写法(推荐)
// const state = {}
// const state = () => {
//   return {}
// }

const state = {
  userInfo: {
    name: 'zs',
    age: 18
  }
}

const getters = {
  upperCaseName (state) {
    return state.userInfo.name.toUpperCase()
  }
}

const mutations = {
  setUserInfo (state, newUserInfo) {
    state.userInfo = newUserInfo
  }
}

const actions = {
  setUserInfoAsync (store, newUserInfo) {
    setTimeout(() => {
      store.commit('setUserInfo', newUserInfo)
    }, 1000)
  }
}

// 最后需要把配置项 进行导出操作
// export default {
//   state: state,
//   getters: getters,
//   mutations: mutations,
//   actions: actions
// }

export default {
  // namespaced 区分下命名空间
  namespaced: true,
  state,
  getters,
  mutations,
  actions
}
